//
//  CustomAlertView.m
//  jayme
//
//  Created by Tyrion on 6/4/15.
//  Copyright (c) 2015 ND. All rights reserved.
//

#import "CustomAlertView.h"
#import <Masonry/Masonry.h>
#import "UIView+WindowAlert.h"

@implementation CustomAlertView

-(id) initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if ( self) {
        [self ConstructView];
    }
    return self;
    
}


-(void)ConstructView{

    CGFloat width = self.frame.size.width;
//    self.layer.borderWidth = 1;
    self.layer.cornerRadius = 5.f;
    self.backgroundColor = [UIColor whiteColor];
    
    self.titleLable = [[UILabel alloc] init];
    [self addSubview: self.titleLable];
    [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make){
        
//        make.center.equalTo(self);
        make.left.equalTo(self.mas_left).offset(0);
        make.right.equalTo(self.mas_right).offset(0);
        make.top.equalTo(self.mas_top).offset(10);
        make.height.equalTo(@50);
    }];
//    self.titleLable.layer.borderWidth = 1;
    self.titleLable.textAlignment = NSTextAlignmentCenter;
    
    self.cancelBtn = [[UIButton alloc] init];
    self.cancelBtn.backgroundColor = [UIColor colorWithRed:0.86 green:0.86 blue:0.87 alpha:1];
//    self.cancelBtn.titleLabel.text = @"取消";
    [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [self addSubview:self.cancelBtn];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.equalTo(self.titleLable.mas_bottom).offset(5);
        make.left.equalTo(self.mas_left).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(0);
        make.width.equalTo(@(width/2));
//        make.height.equalTo(@50);
    }];
    [self.cancelBtn addTarget:self action:@selector(doCancel:) forControlEvents:UIControlEventTouchUpInside];
//    self.cancelBtn.layer.borderWidth = 1;
    
    self.confirmBtn = [[UIButton alloc] init];
    self.confirmBtn.backgroundColor = [UIColor colorWithRed:0.86 green:0.28 blue:0.5 alpha:1];
//    self.confirmBtn.titleLabel.text = @"确定";
    [self.confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    [self addSubview: self.confirmBtn];
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.equalTo(self.titleLable.mas_bottom).offset(5);
        make.right.equalTo(self.mas_right).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(0);
        make.width.equalTo(@(width/2));
//        make.height.equalTo(@50);
    }];
    [self.confirmBtn addTarget:self action:@selector(doConfirm:) forControlEvents:UIControlEventTouchUpInside];
//    self.confirmBtn.layer.borderWidth = 1;
}


-(IBAction)doCancel:(id)sender{
    [self removeFromWindow];
}

-(IBAction)doConfirm:(id)sender{
    [self removeFromWindow];
    [self.delegate doAlertConfirm];
}

@end
